function formatDate (strTime) {
    if(strTime == null)
        return "";
    var date = new Date(strTime);
    return date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();
}
function formatTime (strTime) {
    if(strTime == null)
        return "";
    var date = new Date(strTime);
    return date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
}
function inquireOrderInfo(Url) {
    var inquire_image={};
    var status="";
    var demand_number;
    var demand_person;
    var demand_phone;

    //获取元素值
    demand_number=$(".inquire-number").val();
    if(demand_number != null && demand_number != "")
        inquire_image.orderNo=demand_number;

    demand_person=$(".inquire-receiver").val();
    if(demand_person != null && demand_person != "")
        inquire_image.toName=demand_person;

    demand_phone=$(".inquire-tel").val();
    if(demand_phone != null && demand_phone != "")
        inquire_image.cellphone=demand_phone;

    $("input[name='inquire-chose']:checked").each(function () {
        status += this.value + ",";
    });
    if(status.length > 1){
        status = status.substring(0,status.length - 1);
        inquire_image.status=status;
    }

    //移除上次查询结果
    $(".add").remove();

    //获取数据
    $.getJSON(Url,inquire_image,function(data){
        if(data.success){
            for(var i=0;i<data.order.length;i++){
                var msg;
                if(data.order[i].middleMessage==null&&data.order[i].receiveMessage==null){
                    msg=""
                }else{
                    msg=data.order[i].middleMessage==null?data.order[i].receiveMessage:data.order[i].middleMessage;
                }
                $(".table-inquire").append(
                    "<tr class='add'>"+
                    "<td><div class='dropdown'>" +
                    "<button id='dLabel' type='button' data-toggle='dropdown' aria-haspopup='true' aria-expanded='false' class='icon-plus'></button>" +
                    "<div class='panel dropdown-menu' aria-labelledby='dLabel'>" +
                    "<div class='panel-body'>" +
                    "<table class='table table-bordered' >" +
                    "<tr>" +
                    "<th>出发支站点及录入时间</th>" +
                    "<th>中转站点及中转时间</th>" +
                    "<th>打包人及打包时间</th>" +
                    "<th>到达站点及到达时间</th>" +
                    "<th>派件站点及派件时间</th>" +
                    "</tr>" +
                    "<tr><td>"+(data.order[i].user==null?"":data.order[i].user.stationName+"</br>"+formatTime(data.order[i].createDate))+"</td>"+
                    "<td>"+(data.order[i].middleUser==null?"":data.order[i].middleUser.stationName+"</br>"+formatTime(data.order[i].middleDate))+"</td>"+
                    "<td>"+(data.order[i].pack==null?"":data.order[i].pack.packageUserName+"</br>"+formatTime(data.order[i].pack.createTime ))+"</td>"+
                    "<td>"+(data.order[i].receiveUser==null?"":data.order[i].receiveUser.stationName+"</br>"+formatTime(data.order[i].receiveDate))+"</td>"+
                    "<td>"+(data.order[i].deliverUser==null?"":data.order[i].deliverUser.stationName+"</br>"+formatTime(data.order[i].deliverDate))+"</td></tr>"+
                    "</table>" +
                    "</div>" +
                    "</div>" +
                    "</div></td>"+
                    "<td>"+(data.order[i].isQuick?"加急件":"")+"</td>" +
                    "<td>"+data.order[i].orderNo+"</td>"+
                    "<td>"+data.order[i].toName+ "</td>"+
                    "<td>"+data.order[i].cellphone+"</td>"+
                    "<td>"+(data.order[i].city
                    +data.order[i].area
                    +data.order[i].street
                    +data.order[i].address)+"</td>"+
                    "<td>"+msg+"</td>"+
                    "</tr>"
                );
            }
            //清空操作
            $("input[name='inquire-chose']:checked").each(function () {
                if(this.checked==true){
                    $(this).prop('checked', false);
                }
            });
            $(".inquire-number").val("");
            $(".inquire-receiver").val("");
            $(".inquire-tel").val("");
        }
    });
}
$(document).ready(function () {
    $(".btn-inquire-messege").click(function () {
        inquireOrderInfo("../order_queryMidSonOrder.json");
    });
    $(".btn-inquire-messegeForMasterSta").click(function () {
        inquireOrderInfo("../order_qurey.json");
    });
    //清除按钮功能
    $(".btn-inquire-clean").click(function() {
    $("input[name='inquire-chose']:checked").each(function () {
        if(this.checked==true){
            $(this).prop('checked', false);
        }
    });
    $(".inquire-number").val("");
    $(".inquire-receiver").val("");
    $(".inquire-tel").val("");
    });
});